// network的统一出口
import PMRequest from './request'
import { BASE_URL } from './request/config'
import localCache from '@/utils/cache'

const pmRequest = new PMRequest({
  baseURL: BASE_URL,
  timeout: 5000,
  interceptor: {
    requestInterceptor(config) {
      // console.log('请求成功拦截')
      const token = localCache.getCache('token')
      if (token) {
        if (config.headers) {
          config.headers.Authorization = `Bearer ${token}`
        }
      }
      return config
    },
    requestInterceptorCatch(error) {
      // console.log('请求失败拦截')
      return error
    },
    responseInterceptor(config) {
      // console.log('响应成功拦截')
      return config
    },
    responseInterceptorCatch(error) {
      // console.log('响应失败拦截')
      return error
    }
  }
})

export default pmRequest
